package edu.uba.fcen.estimacion.word.selection.filter;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;

import org.apache.log4j.Logger;

import edu.uba.fcen.estimacion.word.selection.constants.Constants;


public class NormalLineByLine implements FilterWords {

	private static Logger logger = Logger.getLogger(WikipediaFilterWords.class); 
	private String path;
	private BufferedReader in;
	
	//TODO change this string for a path object this is not possible until i use Java 7
	public NormalLineByLine(String path) {
		this.path = path;
		logger.info("Ready to read file in path: " + this.path);
		this.init();
	}
	
	@Override
	public String readLine() {
		String line = null;
		try {
			line = this.in.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return line;
	}
	
	private void init() {
		try {
			Reader in = new InputStreamReader(new FileInputStream(this.path), Constants.ENCODING);
			this.in = new BufferedReader(in);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}

}
